/**
* @description : 案件选择
* @descriptionDetail : 案件选择
* @copyright : 浙江烟草
* @author : mc
* @create : 2022-12-05 15:53:30
*/
<template>
	<view>
		<!-- #ifdef H5-ONLY -->
		<theme-navbar :is-white="false" :title="navTitle" :custom-back="goBack" style="z-index: 99999">
			<view class="nav-right-icon">
				<u-icon name="checkbox-mark" color="#FFF" size="38" @tap="confirm"></u-icon>
			</view>
		</theme-navbar>
		<!-- #endif -->
		<!-- #ifdef H5-WECHAT || H5-EMP -->
		<fab-button :content="fContent" @fabtrigger="fabtrigger" />
		<!-- #endif -->
		<view class="search-ctn">
			<view class="key-search">
				<u-search bg-color="#fff" shape="round" :clearabled="true" actionText="确定" :showAction="true" :animation="true" placeholder="案件名称/案件编号" v-model="searchKey" @custom="toSearchList"></u-search>
			</view>
			<view class="u-gap-la"></view>
		</view>
		<view class="content">
			<list-view :i="0" :index="0" :load-data="loadData" :init-load="false" ref="mescrollItem0">
				<view :class="[selectObj.caseCode == d.data.caseCode ? 'lt-root-select-bg':'']" class="list-item-root" slot-scope="d">
					<view class="lt-root" @tap="itemClick(d.data)">
						<view class="lt-row-space">
							<view>
								<text class="lt-left-label">
									案件编号：
								</text>
								<text class="lt-right-value">
									{{ d.data.caseCode }}
								</text>
							</view>
						</view>
						<view class="lt-row">
							<text class="lt-left-label">
								案件名称：
							</text>
							<text class="lt-right-value">
								{{ d.data.caseName }}
							</text>
						</view>
						<u-row gutter="0" style="margin: 10rpx 0;">
							<u-col span="6">
								<view class="lt-left-label">
									涉案金额(万元)：
								</view>
								<view class="lt-right-value mf-o">
									{{ d.data.caseMoney }}
								</view>
							</u-col>
							<u-col span="6">
								<view class="lt-left-label">
									查获车辆数：
								</view>
								<view class="lt-right-value mf-o">
									{{ d.data.caseCar }}
								</view>
							</u-col>
						</u-row>
						<u-row gutter="0" style="margin: 10rpx 0;">
							<u-col span="6">
								<view class="lt-left-label">
									实物金额（万元）：
								</view>
								<view class="lt-right-value mf-o">
									{{ d.data.goodsMoney }}
								</view>
							</u-col>
							<u-col span="6">
								<view class="lt-left-label">
									是否网络案件：
								</view>
								<view class="lt-right-value mf-o">
									{{ d.data.isNetworkCase == '1' ? '是':'否' }}
								</view>
							</u-col>
						</u-row>
					</view>
				</view>
			</list-view>
		</view>
	</view>
</template>

<script>
	import MescrollMoreMixin from "@/components/mescroll-uni/mixins/mescroll-more.js";
	import ListView from "@/components/list_view.vue";
	import bigCaseService from "@/service/case/bigCase.service.js";
	import fabButton from '@/components/uni-fab.vue';

	export default {
		components: {
			ListView,
			fabButton
		},
		mixins: [MescrollMoreMixin, ],
		data() {
			return {
				searchKey: "",
				selectObj: {},
				from: "",
				fContent: [{
					iconPath: require('@/static/confirm.png'),
					selectedIconPath: require('@/static/confirm.png'),
					text: '确定',
					active: false,
				}],
			}
		},
		onLoad(opt) {
			this.from = opt.from;
		},
		mounted() {
			this.setRightBtn();
		},
		methods: {
			setRightBtn() {
				// #ifdef H5-DINGDING
				this.$deviceApi.setRight("确定", () => {
					this.confirm();
					this.setRightBtn();
				}, true, true);
				// #endif
			},
			fabtrigger(btn) {
				if (btn.index == 0) {
					this.confirm();
				}
			},
			getListViewTop() {
				let p = uni.upx2px(64) + uni.upx2px(10);
				return p + "px";
			},
			getListViewBottom() {
				return uni.upx2px(140) + 10;
			},
			toSearchList(e) {
				this.getMescroll(0).triggerDownScroll();
			},
			itemClick(itm) {
				if (this.selectObj.caseCode == itm.caseCode) {
					this.selectObj = {};
				} else {
					this.selectObj = itm;
				}
			},
			// 用的工作待办接口筛选数据，不用做分页查询，默认多查一批数据出来
			loadData(page) {
				// "已上报案件"参数
				let paras_query = {
					normalCase: 1,
					notTrans: 1,
					bigCase: 1,
					cmdCase: 1,
					fakeCig: 1,
					limitTime: 1,
				};
				// 关联案件参数
				if (this.from == 'association') {
					paras_query = {
						cmdCase: 1,
						normalCase: 1,
					}
				}
				let param = {
					limit: page.size,
					page: page.num,
					paras: paras_query,
				}
				if (this.$u.test.number(this.searchKey)) {
					param.paras.caseCode = this.searchKey;
				} else {
					param.paras.caseName = this.searchKey;
				}
				return new Promise((resolve, reject) => {
					bigCaseService.getNetCaseList(param).then(res => {
						if (res.success) {
							resolve({
								data: {
									totalCount: res.count,
									list: res.data,
								},
							})
						} else {
							this.$u.toast(res.msg);
							resolve({
								data: {
									totalCount: 0,
									list: [],
								},
							})
						}
					}).catch(e => {
						console.log(e);
						resolve({
							data: {
								totalCount: 0,
								list: [],
							},
						})
					});
				});
			},
			confirm() {
				if (this.$u.test.isEmpty(this.selectObj)) {
					this.$u.toast("请选择一项");
					return;
				}
				this.$modal.showLoading('请稍后...');
				bigCaseService.checkCaseRepeat([this.selectObj, ], {
					type: "bigCase",
				}).then(res => {
					this.$modal.hideLoading();
					if (res.success) {
						if (!this.$u.test.isEmpty(res.bean)) {
							this.$u.toast('该案件已关联,请选择其他案件');
						} else {
							this.backPrev({
								paramKey: "selectCase",
								param: {
									data: this.selectObj,
									from: this.from,
								},
							});
						}
					} else {
						this.$u.toast(res.msg);
					}
				}).catch(e => {
					console.log(e);
					this.$modal.hideLoading();
					this.$u.toast("检查失败:" + JSON.stringify(e));
				});
			},
		},
	}
</script>

<style scoped lang="scss">
	@import "@/style/common/rightMenu.scss";

	.mf-o {
		margin-left: 0 !important;
		padding-top: 14rpx;
	}

	.content {
		background-color: #f3f4f5;
		/* #ifdef H5-DINGDING || H5-WECHAT  */
		padding-top: 74rpx;
		/* #endif */
		/* #ifdef H5-ONLY  */
		padding-top: calc(44rpx + 41px);
		/* #endif */
	}

	.key-search {
		width: 100%;
		background-color: white;
		padding: $cm-search-padding-row $cm-search-padding-column;
	}

	.search-ctn {
		width: 100%;
		position: fixed;
		z-index: 999;
		/* #ifdef H5-DINGDING || H5-WECHAT  */
		top: 0;
		/* #endif */
		/* #ifdef H5-ONLY  */
		top: 44px;
		/* #endif */
	}

	.list-item-root {
		margin: 10px;
		border-radius: 15px;
		background-color: white;
		padding: $cm-conent-padding-column $cm-content-paddng-row;
	}

	.lt-root {
		display: flex;
		flex-direction: column;
		width: 100%;
	}

	.lt-root-select-bg {
		background-color: $u-type-primary-disabled;
	}

	.lt-row {
		display: inline-flex;
		width: 100%;
		flex-direction: row;
		justify-content: flex-start;
		margin: 10rpx 0;
	}

	.lt-row-space {
		display: inline-flex;
		width: 100%;
		flex-direction: row;
		justify-content: space-between;
		margin: 10rpx 0;
	}

	.lt-title {
		font-size: 36rpx;
		font-weight: 600;
		margin: 10rpx 0;
		color: $u-main-color;
	}

	.lt-subtitle {
		font-size: 28rpx;
		font-weight: 400;
		margin: 10rpx 0;
		color: $cm-form-subtitle-color;
	}

	.lt-left-label {
		font-size: 28rpx;
		font-weight: 400;
		flex-shrink: 0;
		color: $cm-form-item-label-color;
	}

	.lt-right-title-label {
		font-size: 28rpx;
		margin: 10rpx 0;
		color: $u-main-color;
	}

	.lt-right-title-value {
		margin-left: 16rpx;
		font-size: 32rpx;
		font-weight: 400;
		color: $u-type-warning-dark;
	}

	.lt-right-value {
		margin-left: 16rpx;
		font-size: 28rpx;
		font-weight: 400;
		color: $u-main-color;
	}

	.lt-row-margin-tb {
		margin-top: 10rpx;
		margin-bottom: 10rpx;
	}

	.u-gap-la {
		background-color: #f3f4f5;
		height: 11px;
	}
</style>
